import 'package:flutter/material.dart';
import 'package:one_flutter/MyAppBar.dart';

/**
 * 页面参数传递
 * */

class Product {
  final String name;
  final String imgUrl;

  Product(this.name, this.imgUrl);
}

class ProductList extends StatelessWidget {
  List<Product> productLists;

//
//  ProductList({Key key,@required this.productLists}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    productLists = getProductList();
    return Scaffold(
      appBar: CommonBar(title: '商品列表'),
      body: ListView.builder(
        itemCount: productLists.length,
        itemBuilder: (context, index) {
          return ListTile(
            leading: Image.network(
              productLists[index].imgUrl,
            ),
            title: Text(productLists[index].name),
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (BuildContext context) {
                    return ProductDetails(product: productLists[index]);
                  }));
            },
          );
        },
      ),
    );
  }

  List<Product> getProductList() {
    var productList = List<Product>();
    productList.add(Product('商品1',
        'https://img.alicdn.com/imgextra/i2/128677059/O1CN01MqcAl22214QuMwvji_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品2',
        'https://img.alicdn.com/imgextra/i1/1232040116/O1CN01OpdLQf1CjAYepFdjW_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品3',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01oMDld91IhEZrGiuau_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品4',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品5',
        'https://img.alicdn.com/imgextra/i2/128677059/O1CN01MqcAl22214QuMwvji_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品6',
        'https://img.alicdn.com/imgextra/i1/1232040116/O1CN01OpdLQf1CjAYepFdjW_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品7',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01oMDld91IhEZrGiuau_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品8',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品9',
        'https://img.alicdn.com/imgextra/i2/128677059/O1CN01MqcAl22214QuMwvji_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品10',
        'https://img.alicdn.com/imgextra/i1/1232040116/O1CN01OpdLQf1CjAYepFdjW_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品11',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01oMDld91IhEZrGiuau_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品12',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品8',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品9',
        'https://img.alicdn.com/imgextra/i2/128677059/O1CN01MqcAl22214QuMwvji_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品10',
        'https://img.alicdn.com/imgextra/i1/1232040116/O1CN01OpdLQf1CjAYepFdjW_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品11',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01oMDld91IhEZrGiuau_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品12',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品8',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品9',
        'https://img.alicdn.com/imgextra/i2/128677059/O1CN01MqcAl22214QuMwvji_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品10',
        'https://img.alicdn.com/imgextra/i1/1232040116/O1CN01OpdLQf1CjAYepFdjW_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品11',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01oMDld91IhEZrGiuau_!!0-saturn_solar.jpg_220x220.jpg'));
    productList.add(Product('商品12',
        'https://img.alicdn.com/imgextra/i3/125020924/O1CN01dAQBKq1IhEZS7yHet_!!0-saturn_solar.jpg_220x220.jpg'));
    return productList;
  }
}

class ProductDetails extends StatelessWidget {
  final Product product;

  ProductDetails({Key key, @required this.product}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: CommonBar(title: '${product.name}'),
      body: Center(
        child: Image.network('${product.imgUrl}'),
      ),
    );
  }
}
